<template>
  <div id="test6" style="display:flex;flex-grow:1;height: 100%; width:100%">
    <el-card style="height:100%; width:100%">
      <el-row>
        <el-col :span="2">
          <el-button @click="handleQuery" type="primary" plain>查询</el-button>
        </el-col>
        <el-col :span="2">
          <el-button @click="dialognewVisible = true" type="primary" plain>新增</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" plain>导入</el-button>
        </el-col>
        <el-col :span="2">
          <el-button @click="handleQueryRest" type="primary" plain>重置</el-button>
        </el-col>
      </el-row>

      <el-row style="margin-top: 20px">
        <el-col :span="2" style="margin-top: 10px">
          <span>教师名称:</span>
        </el-col>
        <el-col :span="4">
          <el-input v-model="queryData.name" placeholder="请输入教师名称" style="width: 200px"></el-input>
        </el-col>
        <el-col :span="2" style="margin-top: 10px">
          <span>教师类型:</span>
        </el-col>
        <el-col :span="4">
          <el-input v-model="queryData.role" placeholder="请输入教师类型" style="width: 200px"></el-input>
        </el-col>
        <el-col :span="2" style="margin-top: 10px">
          <span>搜索科目:</span>
        </el-col>
        <el-col :span="4">
          <el-input placeholder="请输入搜索科目" style="width: 200px"></el-input>
        </el-col>
        <el-col :span="2" style="margin-top: 10px">
          <span>教师卡号:</span>
        </el-col>
        <el-col :span="4">
          <el-input v-model="queryData.number" placeholder="请输入教师卡号" style="width: 200px"></el-input>
        </el-col>
      </el-row>
      <el-row style="margin-top: 20px">
        <el-col :span="2" style="margin-top: 10px">
          <span>教师手机:</span>
        </el-col>
        <el-col :span="5">
          <el-input v-model="queryData.phone" placeholder="请输入教师手机" style="width: 200px"></el-input>
        </el-col>
      </el-row>
      <el-table :data="pageInfo.list" style="width: 100%; margin-top: 20px">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="teacherName" label="教师姓名"></el-table-column>
        <el-table-column prop="photoUrl" label="教师照片"></el-table-column>
        <el-table-column prop label="学校名称"></el-table-column>
        <el-table-column prop label="授课科目"></el-table-column>
        <el-table-column prop label="授课班级"></el-table-column>
        <el-table-column prop label="班主任代理班级"></el-table-column>
        <el-table-column prop="role" label="教师类型"></el-table-column>
        <el-table-column prop="phone" label="教师手机号码"></el-table-column>
        <el-table-column prop label="教师账号"></el-table-column>
        <el-table-column prop="number" label="教师卡号"></el-table-column>
        <el-table-column align="center" fixed="right" label="操作" width="150px">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleCheck(scope.row)">编辑</el-button>
            <el-button type="text" size="small" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageInfo.pageNum"
          :page-size="pageInfo.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="pageInfo.total"
        ></el-pagination>

        <!--新增学生弹出框-->
        <el-dialog title="新增教师" :visible.sync="dialognewVisible" center width="40%">
          <el-form
            class="newTeacherForm"
            label-width="80px"
            :model="newTeacherForm"
          >
            <el-form-item label="姓名">
              <el-input v-model="newTeacherForm.name"></el-input>
            </el-form-item>
            <el-form-item label="号码">
              <el-input v-model="newTeacherForm.number"></el-input>
            </el-form-item>
            <el-form-item label="电话号码">
              <el-input v-model="newTeacherForm.phone"></el-input>
            </el-form-item>
            <el-form-item label="学校">
              <el-input v-model="newTeacherForm.school"></el-input>
            </el-form-item>
            <el-form-item label="教师类型">
              <el-input v-model="newTeacherForm.role"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="handleAdd">新增</el-button>
            <el-button @click="handleAddRest">重置</el-button>
          </div>
        </el-dialog>
      </div>
    </el-card>
  </div>
</template>
<script>
import { queryTeacher, addTeacher, deleteTeacher } from "@/api/xiaowu";
export default {
  name: "Student",
  //组件创建
  created() {},
  mounted() {
    this.getList();
  },
  data() {
    return {
      /**遮罩层 */
      loading: false,
      /**教师信息编辑弹窗可见性 */
      dialogVisible: false,
      /**新增教师信息弹窗可见性 */
      dialognewVisible: false,
      /**教师记录列表 */
      pageInfo: {},
      /**查询参数 */
      queryData: {
        name: "",
        number: "",
        phone: "",
        role: "",
        school: "66",
        pageSize: "5",
        pageNum: "1",
      },
      /**新增参数 */
      newTeacherForm: {
        name: undefined,
        number: undefined,
        phone: undefined,
        role: undefined,
        school: undefined,
      }
    };
  },
  methods: {
    /**查询记录列表 */
    getList() {
      this.loading = true;
      queryTeacher(this.queryData).then((response) => {
        this.pageInfo = response.data.pageInfo;
        this.loading = false;
      });
    },
    /** 查询按钮操作 */
    handleQuery() {
      // this.queryData.startTime = this.timePicker[0];
      // this.queryData.endTime = this.timePicker[1];
      console.log(this.queryData);
      this.getList();
      this.$message.success("查询成功");
      this.handleQueryRest();
    },
    /**新增记录 */
    handleAdd() {
      console.log(this.newTeacherForm);
      addTeacher(this.newTeacherForm);
      this.handleAddRest();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm(
        '是否确认删除教师"' + row.teacherName + '"的信息?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          console.log(row.id);
          return deleteTeacher(row.id);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
    /**返回复选框数据 */
    selectionChange(val){
      this.selectArr = [];
      console.log('val',val);
      val.map((item) => {
        this.selectArr.push(item.id)
      })
      // this.selectArr = val;
      console.log("selectArr",this.selectArr);
    },
    /**批量删除 */
    deleteSelectionChange(){
      console.log("selectArr",this.selectArr);
      this.getList();
    },
    /**重置查询表单 */
    handleQueryRest() {
      this.queryData = {
        name: "",
        number: "",
        phone: "",
        role: "",
      };
    },
    /**重置新增表单 */
    handleAddRest() {
      this.newTeacherForm = {
        name: undefined,
        number: undefined,
        phone: undefined,
        role: undefined,
        school: undefined,
      }
    },
    /** 处理分页 */
    handleSizeChange(val) {
      this.queryData.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val;
      this.getList();
    },
  },
};
</script>
<style lang="less" scoped>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
